package io.shallwe._admin.line;

import org.apache.commons.lang3.StringUtils;

import com.jfinal.aop.Before;
import com.jfinal.aop.Inject;
import com.jfinal.kit.Ret;

import io.shallwe.common.controller.BaseController;
import io.shallwe.common.model.Account;
import io.shallwe.common.model.EnterBuffer;
import io.shallwe.front.EnterService;
/***
   *  入口上线扫描
 * @author 王小伟
 * @date 2019-06-10 21:17:33
 */
public class EnterScanController extends BaseController{

	@Inject 
	EnterScanService service;
	@Inject 
	EnterService enterService;
	
	public void index() {
		checkUrlPara(0);
		render("index.html");
	}
	
	public void list() {
		renderJson(enterService.paginate(0, 100));
	}
	
	public void add() {
		render("add_edit.html");
	}
	
	public void save() {
		EnterBuffer enterBuffer =getBean(EnterBuffer.class,"enterBuffer");
		Account loginAccount = getLoginAccount();
		renderJson(service.save(enterBuffer,loginAccount.getId()));
	}
	
	public void edit() {
		String id=get("id");
		EnterBuffer enterBuffer = service.findById(id);
		set("enterBuffer",enterBuffer);
		render("add_edit.html");
	}
	
	@Before(EnterScanValidator.class)
	public void update() {
		EnterBuffer enterBuffer =getBean(EnterBuffer.class,"enterBuffer");
		Account loginAccount = getLoginAccount();
		renderJson(service.update(enterBuffer,loginAccount.getId()));
	}
	
	public void delete() {
		String id=get("id");
		int type = getInt("type");
		renderJson(service.delete(id,type));
	}
	
	
	public void manualScanPage() {
		render("manualScanPage.html");
	}
	
	
	public void manualScan() {
		String code=get("code");
		String ipAddress=get("ip");
		Ret ret=service.scan(code,ipAddress);

		renderJson(ret);
	}
	
	public void autoScanPage() {
		render("autoScanPage.html");
	}
	
	public void autoScan() {
		String hangerNo=get("code");
		service.autoScan(hangerNo);
		renderJson(Ret.ok("msg","操作成功"));
	}
	
	
}

